<template>
  <div>
    <!-- logo -->
    <div>
      <van-row type="flex" justify="center" class="logo-div">
        <van-col span="18">
          <p class="logo">环境@盒</p>
        </van-col>
      </van-row>
    </div>
    <!--  用户登录信息  -->
    <div class="user-security-info">
      <!--   用户账号   -->
      <van-row type="flex" justify="center" class="user-login-username">
        <van-col span="18">
          <div class="van-hairline--bottom">
            <van-field v-model="userMobile"
                       type="number"
                       placeholder="请输入手机号码"
                       v-bind:left-icon="mobilePhoneIcon"
                       icon="question"
            />
          </div>
        </van-col>
      </van-row>
      <!--   用户密码   -->
      <van-row type="flex" justify="center" class="register-passwd">
        <van-col span="18">
          <div class="van-hairline--bottom">
            <van-field v-model="userPasswd"
                       v-bind:type="showPassword"
                       placeholder="请输入密码"
                       v-bind:password="true"
                       v-bind:left-icon="passwdIcon"
                       v-bind:right-icon="showPasswdIcon"
                       icon="question"
                       @click-right-icon="showPasswordFunction"
            />
          </div>
        </van-col>
      </van-row>
      <!--   验证码   -->
      <van-row type="flex" justify="center" class="sms-code">
        <van-col span="18">
          <div class="van-hairline--bottom">
            <van-field
              v-model="smsCode"
              type="number"
              v-bind:left-icon="smsCodeIcon"
              center
              clearable
              label=""
              placeholder="请输入验证码">
              <template #button>
                <div class="send-sms-code-btn" @click="sendSMS()">
                  <a>{{smsCodeBtnText}}</a>
                </div>
                <!--                <van-button size="small" type="primary">发送验证码</van-button>-->
              </template>
            </van-field>
          </div>
        </van-col>
      </van-row>
      <!--   忘记密码按钮   -->
      <sub-button btnText="忘记密码" @click.native="forgetPasswd"></sub-button>
    </div>
  </div>
</template>
<script>
  import {Toast} from 'vant';
  import SubButton from "@/components/SubButton";

  export default {
    data() {
      return {
        mobilePhoneIcon: require("@/images/mobild-phone-icon@2x.png"),
        passwdIcon: require("@/images/passwd-icon@2x.png"),
        showPasswdIcon: require("@/images/show-passwd@2x.png"),
        smsCodeIcon: require("@/images/smscode-icon@2x.png"),
        showPassword: "password",
        passwordShow: true,
        smsCode: "",
        userMobile: '',
        userPasswd: '',
        smsCodeBtnText: '获取验证码',
        smsCodeBtnChecked: false,
      }
    },
    components: {SubButton},
    methods: {
      onClickLeft() {
        Toast('返回');
      },
      onClickRight() {
        Toast('按钮');
      },
      showPasswordFunction() {
        if (this.showPassword === "password") {
          this.showPassword = "text"
        } else {
          this.showPassword = "password"
        }
      },
      //获取验证码
      sendSMS() {
        let that = this;
        if (!that.smsCodeBtnChecked) {
          that.smsCodeBtnChecked = true;
          if (!that.userMobile) {
            that.$notify('请输入手机号');
            that.smsCodeBtnChecked = false;
            return;
          }
          if (!that.userPasswd) {
            that.$notify('请输入密码');
            that.smsCodeBtnChecked = false;
            return;
          }
          let param = {
            phone: that.userMobile
          }
          let count = 60;
          //定时器倒计时
          let interval = setInterval(() => {
            count--;
            that.smsCodeBtnText = count + 's';
            if (count <= 0) {
              clearInterval(interval)
              that.smsCodeBtnText = '获取验证码';
              that.smsCodeBtnChecked = false;
            }
          }, 1000);
          that.$http.restPost('/sendMessInfo.do', param, that.$http.CONTENT_TYPE.URL_ENCODER).then(response => {
            console.log(response)
          });
        }
      },
      forgetPasswd() {
        let that = this;
        if (!that.userMobile) {
          that.$notify(that.$setNT('请输入手机号').err);
          return;
        }
        if (!that.userPasswd) {
          that.$notify(that.$setNT('请输入密码').err);
          return;
        }
        if (!that.smsCode) {
          that.$notify(that.$setNT('请输入验证码').err);
          return;
        }
        let param = {
          phone: that.userMobile,
          password: that.userPasswd,
          verify: that.smsCode,
          userType: 2
        }
        that.$http.restPost('/modifyPassword.do', param).then(response => {
          console.log(response);
          if (response.data.result > 0) {
            if (response.data.result === 1) {
              that.$notify(that.$setNT('修改成功').suc);
              location.href = 'login.html';
            } else if (response.data.result === 2) {
              that.$notify(that.$setNT('用户已存在').err);
            } else if (response.data.result === 3) {
              that.$notify(that.$setNT('短信验证码有误').err);
            }
          } else {
            that.$notify(that.$setNT('修改失败').err);
          }
        });
      }
    },
  }
</script>
<style lang="css" scoped>

  /* ⬇商标外框⬇ */
  .logo-div {
    margin: 110px 0 60px 0;
  }

  /* ⬇商标⬇ */
  .logo {
    text-align: center;
    line-height: 54px;
    font-size: 54px;
    font-weight: 200;
    font-family: PingFang SC;
    color: rgba(0, 0, 0, 1);
    background: linear-gradient(75deg, rgba(60, 180, 255, 1) 0%, rgba(45, 141, 251, 1) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 0;
  }

  /* ⬇注册-忘记密码⬇ */
  .forget-passwd > * {
    text-align: center;
  }

  .forget-passwd > * > * {
    font-size: 12.5px;
    color: #3198FC;
  }

  .forget-passwd > :first-child {
    text-align: right;
  }

  .forget-passwd > :last-child {
    text-align: left;
  }

  /* ⬇用户信息的块⬇ */
  .user-security-info > * {
    /*margin-bottom: 20px;*/
  }

  /* ⬇用户账号⬇ */
  .user-login-username {
    margin-bottom: 20px;
  }

  /* ⬇用户密码⬇ */
  .register-passwd {
    margin-bottom: 20px;
  }

  /* ⬇短信验证码⬇ */
  .sms-code {
    margin-bottom: 40px;
  }

  /* ⬇ 发送验证码按钮 ⬇ */
  .send-sms-code-btn {
    border-left: 1px solid #3BAFFF;
    padding-left: 10px;
    text-align: center;
  }

  .send-sms-code-btn a {
    color: #2d8dfb;
    font-size: 12px;
  }

  /* ⬇ 注册描述 ⬇ */
  .register-depiction {
    font-size: 10px;
    font-family: PingFang SC;
    font-weight: 400;
    color: rgba(171, 171, 171, 1);
  }

  /* ⬇ 注册描述 ⬇ */
  .privacy-policy {
    font-size: 10px;
    font-family: PingFang SC;
    font-weight: 400;
    color: rgba(59, 175, 255, 1);
    margin-left: 10px;
  }
</style>
